#include<iostream>
#include<algorithm>
using namespace std;
const int N = 2e5+10;
int n;
int v[N];
int mp[10]={1,0,0,0,1,0,1,0,2,1};
bool cmp(int a,int b)
{
    int a1=a;
    int b1=b;
    int ans1=0;
    while(a)
    {
        int q=a%10;
        ans1+=mp[q];
        a/=10;
    }
    int ans2=0;
    while(b)
    {
        int q=b%10;
        ans2+=mp[q];
        b/=10;
    }
    if(ans1==ans2){
        return a1<=b1;
    }
    return ans1<ans2;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
    }
    sort(v,v+n,cmp);
    for(int i=0;i<n;i++){
        cout << v[i] << " ";
    }
    return 0;
}